package com.ssj.ssj.modules.man.controller;

import cn.hutool.core.bean.BeanUtil;
import com.mybatisflex.core.query.QueryWrapper;
import com.ssj.ssj.modules.man.entity.SUser;
import com.ssj.ssj.modules.man.mapper.SUserMapper;
import com.ssj.ssj.modules.man.service.SUserService;
import com.ssj.ssj.util.R;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;


/**
* @author Tiandy
* @since 2023-03-10
*/
@RestController
@RequestMapping("/user")
public class SUserController {

    @Autowired
    private  SUserService userService;

    @Autowired
    private  SUserMapper userMapper;

    /**
     * 查询列表
     */
    @GetMapping(value = "/list")
    public R list(SUser param) {
//        S_USER.NAME.eq("");
        Map<String, Object> map = BeanUtil.beanToMap(param, true, true);
        QueryWrapper query = QueryWrapper.create();
        query.where(map);
        List<SUser> list = userMapper.selectListByQuery(query);
        return R.ok().setData(list);
    }

    /**
     * 分页查询
     * @param param 请求
     */
    @GetMapping(value = "/page")
    public  Object page(SUser param, int pageNo, int pageSize) {
        Map<String, Object> map = BeanUtil.beanToMap(param, true, true);
        QueryWrapper query = QueryWrapper.create();
        query.where(map);
        Object data = userMapper.paginate(pageNo,pageSize, query);
        return R.ok().setData(data);
    }
}
